package com.lyq.database;

import com.lyq.bean.mySql.MysqlLinking;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

public class CheckTableStructure {
    public static void main(String[] args) {
        // 创建数据库连接
        MysqlLinking mysqlLinking = new MysqlLinking();
        mysqlLinking.getLink();
        Connection conn = MysqlLinking.conn;
        
        if (conn != null) {
            System.out.println("数据库连接成功！");
            
            try {
                // 获取数据库元数据
                DatabaseMetaData metaData = conn.getMetaData();
                
                // 查询course表的列信息
                ResultSet columns = metaData.getColumns(null, null, "course", null);
                System.out.println("course表的列信息：");
                while (columns.next()) {
                    String columnName = columns.getString("COLUMN_NAME");
                    String dataType = columns.getString("TYPE_NAME");
                    System.out.println("列名: " + columnName + ", 数据类型: " + dataType);
                }
                columns.close();
                
                // 关闭数据库连接
                conn.close();
                System.out.println("数据库连接已关闭。");
            } catch (SQLException e) {
                System.err.println("查询表结构时发生错误: " + e.getMessage());
                e.printStackTrace();
            }
        } else {
            System.err.println("数据库连接失败！");
        }
    }
}